package com.yunhe.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yunhe.bean.CommodityClassify;
import com.yunhe.test.test;

/**
 * Servlet implementation class AddChangeDeleteClassify_Servlet
 */
@WebServlet("/AddChangeDeleteClassify_Servlet")
public class AddChangeDeleteClassify_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddChangeDeleteClassify_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		//增加操作
		if("add".equals(request.getParameter("manage"))){
			String bigid="";
			String smallname="";
			bigid=request.getParameter("cpid");
			int bigId=0;
			if(bigid!=null){
			  bigId=Integer.decode(bigid);		
			}
			smallname=request.getParameter("cname");
			CommodityClassify cc=new CommodityClassify();
			cc.setBig_id(bigId);
			cc.setSmall_name(smallname);
			test te =new test();
			te.AddSmallClassify(cc);
			response.sendRedirect("CommodityClassify_Servlet?manage=showadd");
		}
		//删除大类
		if("deletebig".equals(request.getParameter("manage"))){
			if(request.getParameter("id")!=null){
				int id=Integer.decode( request.getParameter("id"));
				test te=new test();
			    te.deletecla(id);				
			}
	        //页面转到商品展示页
			response.sendRedirect("manage/productClass.jsp");
		}
		//删除小类
		if("deletesmall".equals(request.getParameter("manage"))){
			if(request.getParameter("id")!=null){
				int id=Integer.decode( request.getParameter("id"));
				test te=new test();
			    te.deletecl(id);				
			}
	        //页面转到商品展示页
			response.sendRedirect("manage/productClass.jsp");
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	 doGet(request, response);
	}

}
